home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-06 | 6.8 KB | 327 lines | [TEXT/MPS ] |
- /*
- File: SprocketSample.cp
-
- Contains: Boilerplate application-specific code.
-
- Written by: Dave Falkenburg
-
- Copyright: © 1993-94 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- <7> 12/6/94 DRF Gave this file a better name. Also stop defining kCreditsBox
- here.
- <6> 11/8/94 DRF (LDR) Modified to pass all non-standard menu selections through
- to window obj.
- <5> 11/8/94 DRF DoEditMenu is gone; call DoMenuSelection instead.
- <4> 9/28/94 DRF Changes for Dave Mark: More comments & rearranged code.
- <3> 9/27/94 DRF Changes for Dave Mark: AppLib.h is now Sprocket.h &
- clipboard conversion routines are fixed.
- <2> 9/9/94 DRF Reorganized headers and removed redundant #includes and
- conditionalized AOCE support.
- */
-
- #include "Sprocket.h"
- #include "Window.h"
- #include "StandardMenus.h"
- #include "SplashWindow.h"
-
- #include <Desk.h>
- #include <Resources.h>
- #include <Errors.h>
-
- #include "ToolWindow.h"
- #include "DocWindow.h"
- #include "PreferencesDialogWindow.h"
- #include "MailableDocWindow.h"
-
- AppPreferences gPreferences;
-
- // Function Prototypes:
-
- void AboutBox(void);
- void OpenExistingDocument(void);
-
-
- #define mDebug 256
- #define iNewMailableWindow 1
-
- #define kAboutBoxFor68K 256
- #define kAboutBoxForPowerPC 257
- #define iCreditsButton 2
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // SetupApplication
- //
- // Modify this function to provide any application-specific
- // initialization you may require.
- //
- // This is a good place to call EnterMovies, allocate
- // sound channels, setup network things, etc.
-
- OSErr
- SetupApplication(void)
- {
- InsertMenu(GetMenu(mDebug),0); // Add Debug Menu
-
- #if qAOCEAware
- if (gHasAOCE)
- EnableItem(GetMHandle(mDebug),1);
- #endif
-
- TToolWindow * someTools = new TToolWindow(1025);
-
- gPreferences.fMailPreferences.fCreateMailerForNewDocuments = true;
-
- InitCursor();
- return (noErr);
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // TearDownApplication
- //
- // Modify this function to tear down anything that you allocated
- // from within SetupApplication.
-
- void
- TearDownApplication(void)
- {
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // HandleMenu
- //
- // Modify this function to handle any menu commands you might add
- // to Sprocket’s default menubar. This isn’t the greatest strategy,
- // but works for most things.
-
- void
- HandleMenu(TWindow * topWindowObj, long menuCode)
- {
- short menu = (short) (menuCode >> 16);
- short item = (short) (menuCode & 0xffff);
- Str255 deskAccName;
-
- switch (menu)
- {
- case mApple:
- switch (item)
- {
- case iAbout:
- AboutBox();
- break;
-
- default:
- GetItem(GetMHandle(mApple),item,deskAccName);
- (void) OpenDeskAcc(deskAccName);
- break;
- }
- break;
-
- case mFile:
- switch (item)
- {
- case iNew:
- CreateNewDocument();
- break;
-
- case iOpen:
- OpenExistingDocument();
- break;
-
- case iClose:
- HandleClose(FrontNonFloatingWindow());
- break;
-
- case iPreferences:
- TPreferencesDialogWindow * prefsDialog = new TPreferencesDialogWindow;
- break;
-
- case iQuit:
- gDone = true;
- break;
-
- default:
- break;
- }
- break;
-
- case mEdit:
- switch (item)
- {
- case iShowOrHideClipboard:
- break;
-
- default:
- if ((!SystemEdit(item-1)) && (topWindowObj != nil))
- topWindowObj->DoMenuSelection(menu,item);
- break;
- }
-
- case mDebug:
- switch(item)
- {
- case iNewMailableWindow:
- #if qAOCEAware
- TMailableDocWindow *aWackyThing = new TMailableDocWindow;
- #endif
- break;
-
- default:
- break;
- }
- break;
-
- default:
- if (topWindowObj != nil)
- topWindowObj->DoMenuSelection(menu, item);
- break;
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // ReadLocalClipboardFromScrap & WriteLocalClipboardToScrap
- //
- // These functions will be called whenever the user switches into
- // or out of your application.
- //
- // If you keep copy of the clipboard in your own data structures,
- // these functions will allow you to keep it in synch so that the
- // user can cut and paste information between your program and
- // other applications.
- //
- // We don’t actually use the clipboard in Sprocket, so these
- // functions are empty for now.
-
- void
- ReadLocalClipboardFromScrap(void)
- {
- }
-
- void
- WriteLocalClipboardToScrap(void)
- {
- }
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // CreateNewDocument, OpenDocument, PrintDocument, and
- // QuitApplication.
- //
- // These functions will be called whenever one of the required
- // AppleEvents is sent to your application— either when your
- // program is launched, or when the user opens a document from
- // the Finder.
-
- OSErr
- CreateNewDocument(void)
- {
- TDocWindow *aNewWindow = new TDocWindow();
-
- if (aNewWindow)
- return noErr;
- else
- return memFullErr;
- }
-
-
- OSErr
- OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
- {
- // Normally, you would open the file (or letter) and use the
- // information to create windows, etc.
-
- // For now, we just create a new document.
-
- return CreateNewDocument();
- }
-
-
- OSErr
- PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
- {
- // We don’t do printing yet, but you could.
- return errAEEventNotHandled;
- }
-
-
- Boolean
- QuitApplication(void)
- {
- // Just go ahead and say we’re done quitting…
-
- // Normally, you would offer to close any unsaved documents,
- // allowing the user to cancel along the way.
-
- return true;
- }
-
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // AboutBox
- //
- // Put up our about box, including the version number. Depending
- // on what version we are running, pick the correct DLOG resource.
- //
-
- void
- AboutBox(void)
- {
- Handle versionHandle;
- StringPtr nullStr = (StringPtr) "\p";
- StringPtr shortVersionString = nullStr;
- short itemHit;
-
- versionHandle = GetResource('vers',1);
- if (versionHandle)
- shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
- ParamText(shortVersionString,nullStr,nullStr,nullStr);
- ReleaseResource(versionHandle);
-
- #ifndef powerc
- itemHit = StandardAlert(kAboutBoxFor68K);
- #else
- itemHit = StandardAlert(kAboutBoxForPowerPC);
- #endif
-
- if (itemHit == iCreditsButton)
- StandardAlert(kCreditsBox);
- }
-
-
-
- ////////////////////////////////////////////////////////////////////
- //
- // OpenExistingDocument
- //
- // Use StandardFile to ask the user for a file to open. We use
- // CustomGetFile so that we can properly handle update events
- // in other windows while the dialog is active.
-
- void
- OpenExistingDocument(void)
- {
- StandardFileReply reply;
- SFTypeList ourTypes;
-
- Point where = { -1, -1 };
-
- HiliteWindowsForModalDialog(false);
- CustomGetFile((FileFilterYDUPP) nil, -1, ourTypes, &reply, 0, where,
- (DlgHookYDUPP) nil,StandardDialogFilterYD, nil,nil,nil);
- HiliteWindowsForModalDialog(true);
- }
-
-
-